package com.pig4cloud.pig.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.pig4cloud.pig.admin.api.entity.PrDeviceDeptEntity;
import com.pig4cloud.pig.admin.service.PrDeviceDeptService;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 设备单位中间表
 *
 * @author pig
 * @date 2025-06-04 23:40:16
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/prDeviceDept" )
@Tag(description = "prDeviceDept" , name = "设备单位中间表管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class PrDeviceDeptController {

    private final  PrDeviceDeptService prDeviceDeptService;



    /**
     * 新增设备单位中间表
     * @param prDeviceDept 设备单位中间表
     * @return R
     */
    @Operation(summary = "新增设备单位中间表" , description = "新增设备单位中间表" )
    @SysLog("新增设备单位中间表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('admin_prDevice_add')" )
    public R save(@RequestBody PrDeviceDeptEntity prDeviceDept) {
        return R.ok(prDeviceDeptService.save(prDeviceDept));
    }


    /**
     * 通过id删除设备单位中间表
     * @param prDeviceDept ${pk.attrName}列表
     * @return R
     */
    @Operation(summary = "通过id删除设备单位中间表" , description = "通过id删除设备单位中间表" )
    @SysLog("通过id删除设备单位中间表" )
    @PostMapping("remove")
    @PreAuthorize("@pms.hasPermission('admin_prDevice_del')" )
    public R remove(@RequestBody PrDeviceDeptEntity prDeviceDept) {
        return R.ok(prDeviceDeptService.remove(new LambdaQueryWrapper<PrDeviceDeptEntity>().eq(PrDeviceDeptEntity::getDeviceId,prDeviceDept.getDeviceId()).eq(PrDeviceDeptEntity::getDeptId,prDeviceDept.getDeptId())));
    }



}
